import { defineStore } from 'pinia'
import { reactive } from 'vue'


const useAdmin = defineStore('admin', () => {
    const defaultAdmin = {
        username: '',
        avatar: ''
    }
    const admin = reactive(Object.assign({}, defaultAdmin))
    const updateAdmin = options => {
        Object.assign(admin, options)
        return admin
    }
    const updateAvatar = (newAvatar) => {
        admin.avatar = newAvatar; // 更新头像
        return admin; // 返回更新后的 admin 对象
    }
    const removeAdmin = () => {
        Object.assign(admin, defaultAdmin)
        return admin
    }
    return { admin, updateAdmin, removeAdmin, updateAvatar }
}, {
    persist: {
        enabled: true,
        strategies: [{
            key: 'admin',
            storage: localStorage,
        }]
    }
})
export default useAdmin